import com.yjz.Entity.GoodsEntity;
import com.yjz.Entity.GoodsEntityExample;
import com.yjz.mapper.GoodsEntityMapper;
import com.yjz.mapper.GoodsMapper;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;

import java.util.List;

@Slf4j
public class MybatisSyudy extends BaseTest {

  @Autowired
  private GoodsMapper mapper;

  @Autowired
  private GoodsEntityMapper goodsEntityMapper;

  @Test
  public void test01() {
    log.info("查询结果是:{}", mapper.queryGoodsCount());
  }


  /**
   * @description:测试mybatis-generator 里面的example用法
   * @author :yuanJinZhong
   * @date :2018/8/21-13:41
   */
  @Rollback(false)
  @Test
  public void test02() {
    GoodsEntityExample goodsExample = new GoodsEntityExample();
    //构造查询条件:商品名字不等于空
    goodsExample.createCriteria().andGoodsNameIsNotNull();
    //构造查询条件:distinct
    goodsExample.setDistinct(true);
    //构造排序条件:列名必须是表里面存在的
    goodsExample.setOrderByClause("goods_Name");
    List<GoodsEntity> list = goodsEntityMapper.selectByExample(goodsExample);
    log.info("利用example拼接查询条件得到的查询结果:{}", list);

    GoodsEntity goodsEntity = goodsEntityMapper.selectByPrimaryKey(292);
    log.info("查到的单条结果:{}", goodsEntity);
  }
}
